package code.starivan.leetcode.common;

/**
 * Created by Ivan on 2015/10/19.
 */
public class ListNode {
     public int val;
     public ListNode next;
     public ListNode(int x) { val = x; }

     public void printList(){
          ListNode node=this;
          while (node!=null){
               System.out.print(node.val+" ");
               node=node.next;
          }

          System.out.print("\n");
     }

     public static ListNode construct(int[] data){
          if(data==null||data.length==0){
               return null;
          }

          ListNode head=new ListNode(data[0]);
          ListNode pre=head;
          for(int i=1;i<data.length;++i){
               ListNode node=new ListNode(data[i]);
               pre.next=node;
               pre=node;
          }

          return head;
     }
}